package com.uniledger.exchange.home.scheme;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

import com.uniledger.exchange.HomeActivity;
import com.uniledger.exchange.R;
import com.uniledger.exchange.base.activity.BaseActivity;
import com.uniledger.exchange.home.HomeCenter;

import butterknife.BindView;

public class PayFailActivity extends BaseActivity {

    public static void start(Activity activity, PayResult payResult) {
        Intent intent = new Intent(activity, PayFailActivity.class);
        intent.putExtra("PayThirdResult", payResult);
        activity.startActivity(intent);
    }

    @BindView(R.id.img_icon)
    ImageView head;

    @BindView(R.id.txt_desc_ok)
    TextView txt_desc_ok;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_fail);
    }

    @Override
    public void initBar() {
        super.initBar();
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        toolbar.setTitle("");
    }

    @Override
    public void getParams() {
        PayResult payResult = getIntent().getParcelableExtra("PayThirdResult");
        if (payResult.flag == HomeCenter.SCHEME_PAYMENT) {
            head.setImageResource(R.drawable.ic_pay_complete);
        }
        txt_desc_ok.setText(payResult.errorMessage);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_pay_complete, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.manger_pay_done) {
            HomeActivity.start(PayFailActivity.this);
            return true;
        } else {
            return super.onOptionsItemSelected(item);
        }
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            //do something.
            return true;
        } else {
            return super.dispatchKeyEvent(event);
        }
    }
}
